package com.hzcx.app.simplechat.util.system;

import android.annotation.SuppressLint;
import android.content.Context;
import android.provider.Settings;
import android.telephony.TelephonyManager;

import com.hzcx.app.simplechat.MyApplication;

public class IMEI {

    @SuppressLint("MissingPermission")
    public static String getDeviceIMEI() {
        String deviceUniqueIdentifier = "";
        try {
            TelephonyManager tm = (TelephonyManager) MyApplication.getContext().getSystemService(Context.TELEPHONY_SERVICE);
            if (null != tm) {
                deviceUniqueIdentifier = tm.getDeviceId();
            }
            if (null == deviceUniqueIdentifier || 0 == deviceUniqueIdentifier.length()) {
                deviceUniqueIdentifier = Settings.Secure.getString(MyApplication.getContext().getContentResolver(), Settings.Secure.ANDROID_ID);
            }
        } catch (Exception e) {
            e.printStackTrace();
            deviceUniqueIdentifier = "未知";
        } finally {
            return deviceUniqueIdentifier;
        }
    }
}
